package edu.xhu.communityantiepidemicsystemback.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import edu.xhu.communityantiepidemicsystemback.common.result.PageResult;
import edu.xhu.communityantiepidemicsystemback.common.result.Result;
import edu.xhu.communityantiepidemicsystemback.dto.*;
import edu.xhu.communityantiepidemicsystemback.entity.Filing;
import edu.xhu.communityantiepidemicsystemback.service.IFilingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lcx
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/filing")
public class FilingController {
    @Autowired
    private IFilingService fileService;
    //查询报备人员
    @PostMapping("/filinglist")
    public PageResult<?> getFiledList(@RequestBody Query query){
        IPage<Filing> filePage = fileService.selectFileList(query);
        return new PageResult<>(filePage.getTotal(),filePage.getRecords());
    }
    //模糊查询
    @PostMapping("/filingfuzzysearch")
    public PageResult<?> fuzzyFilingInfo(@RequestBody Fuzzy fuzzy){
        IPage<Filing> filingIPage= fileService.fuzzyFilingInfo(fuzzy);
        if(Objects.isNull(filingIPage)){
            return new PageResult<>();
        }
        return new PageResult<>(filingIPage.getTotal(),filingIPage.getRecords());
    }
    //添加报备人员
    @PostMapping("/filingadd")
    public Result<?> addFile(@RequestBody CreateFile createFile){
        boolean result=fileService.addFile(createFile);
        if(result){
            return new Result<>().success();
        }else{
            return new Result<>().error("添加成功");
        }

    }
    //删除报备人员
    @GetMapping("/filingdel/{id}")
    public Result<?> delFile(@PathVariable("id") Integer id){
        boolean result=fileService.delFile(id);
        if(result){
            return new Result<>().success();
        }else{
            return new Result<>().error("删除失败，服务器内部错误");
        }
    }
    //修改报备人员信息
    @PostMapping("/filingupdate")
    public Result<?> update(@RequestBody UpdateFile updateFile){
        boolean result=fileService.updateFile(updateFile);
        if(result){
            return new Result<>().success();
        }else{
            return new Result<>().error("修改失败，服务器内部错误");
        }
    }

}
